﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using Library.Entity;
using Gizmox.WebGUI.Forms;

namespace Library
{
    public class UserControlFactory
    {
        Hashtable m_userControlCollection = new Hashtable();
        public const string ADMIN = "Administrator";
        public const string USER = "Manage User";
        public const string BOOK_CATEGORY = "Manage Book Category";
        public const string MEMBER_TYPE = "Manage Member Type";
        public const string MEMBER = "Manage Member";
        public const string BOOK_SHELF = "Manage Book Shelf";
        public const string MEMBER_CLASS = "Manage Member Class";
        public const string BOOK = "Manage Book";
        public const string BOOK_STOCK_ADJUSTMENT = "Book Stock Adjustment";
        public const string BOOK_BORROW = "Book Borrow";
        public const string BOOK_RETURN = "Book Return";
        
        User m_current_user;
        MainForm m_mainForm;

        public UserControlFactory(User current_user, MainForm mainForm)
        {
            m_current_user = current_user;
            m_mainForm = mainForm;
        }
        public UserControl GetUserControl(string key)
        {
            UserControl uc = (UserControl)m_userControlCollection[key];
            if (uc == null)
            {
                switch (key)
                {
                    case USER:
                        m_userControlCollection.Add(key, new UserControlUser(USER, m_current_user, m_mainForm));
                        break;
                    case BOOK_CATEGORY:
                        m_userControlCollection.Add(key, new UserControlBookCategory(BOOK_CATEGORY, m_current_user, m_mainForm));
                        break;
                    case MEMBER_TYPE:
                        m_userControlCollection.Add(key, new UserControlMemberType(MEMBER_TYPE, m_current_user, m_mainForm));
                        break;
                    case BOOK_SHELF:
                        m_userControlCollection.Add(key, new UserControlBookShelf(BOOK_SHELF, m_current_user, m_mainForm));
                        break;
                    case MEMBER_CLASS:
                        m_userControlCollection.Add(key, new UserControlMemberClass(MEMBER_CLASS, m_current_user, m_mainForm));
                        break;
                    case MEMBER:
                        m_userControlCollection.Add(key, new UserControlMember(MEMBER, m_current_user, m_mainForm));
                        break;
                    case BOOK:
                        m_userControlCollection.Add(key, new UserControlBook(BOOK, m_current_user, m_mainForm));
                        break;
                    case BOOK_STOCK_ADJUSTMENT:
                        m_userControlCollection.Add(key, new UserControlBookStockAdjustment(BOOK_STOCK_ADJUSTMENT, m_current_user, m_mainForm));
                        break;
                    case BOOK_BORROW:
                        m_userControlCollection.Add(key, new UserControlBookBorrow(BOOK_BORROW, m_current_user, m_mainForm));
                        break;
                    case BOOK_RETURN:
                        m_userControlCollection.Add(key, new UserControlBookReturn(BOOK_RETURN, m_current_user, m_mainForm));
                        break;
                }
            }
            uc = (UserControl)m_userControlCollection[key];
            return uc;
        }
        public static IList GetFormNames()
        {
            IList m_formNames;
            m_formNames = new ArrayList();
            //m_formNames.Add(USER);
            //m_formNames.Add(USER_ROLE);
            //m_formNames.Add(SOFTMAR);
            return m_formNames;
        }
        public void ClearUserControls()
        {
            m_userControlCollection.Clear();
        }
    }
}